package 集合;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class haxi {
    public static void main(String[] args) {

        Map<String, String> map = new HashMap<>();

        map.put("a", "apple");
        map.put("b", "banana");
        map.put("c", "cherry");

        for (String key : map.keySet()) {
            System.out.println(key + ":" + map.get(key));
        }
        // 通过entrySet进行遍历的方式
        for (Map.Entry<String, String> entry : map.entrySet()) {
            System.out.println(entry.getKey() + ":" + entry.getValue());
        }

        //结合jdk8的stream流进行遍历
        map.entrySet().stream().forEach((entry) -> System.out.println(entry.getKey() + ":" + entry.getValue()));

        //只是遍历value
        for(String value : map.values()) {
            System.out.println(value);
        }
        // lambda表达式遍历
        map.forEach((k,v)->System.out.println(k + ":" + v));

        ConcurrentHashMap<String, String> map1=new ConcurrentHashMap<>();
        map1.put("a", "apple");
    }
}
